Options for pack method are | |
---|---|
column / row |
|
columnspan / rowspan |
|
ipadx, ipady | Internal horizontal and vertical padding. |
padx, pady | External horizontal and vertical padding. |
sticky |
|
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() self.la=Label(self,text="Name") self.la.grid(row=0,column=0,padx=10,pady=10) self.ta=Entry(self,width=30) self.ta.grid(row=0,column=1,padx=10,pady=10,columnspan=2) self.lb=Label(self,text="Address") self.lb.grid(row=1,column=0,padx=10,pady=10) self.tb=Entry(self,width=30) self.tb=Entry(self,width=30) self.tb.grid(row=1,column=1,padx=10,pady=10,columnspan=2) self.b1=Button(self,text="Save") self.b1.grid(row=2,column=1,padx=10,pady=10,sticky='W') self.b2=Button(self,text="Cancel") self.b2.grid(row=2,column=2,padx=10,pady=10,sticky='E') frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() fnt="Monospaced 15 bold" lst=["Name","Address","City","ContactNo","EmailID"] r=0 for nm in lst: lbl=Label(self,text=nm,font=fnt) lbl.grid(row=r,column=0,sticky="W",padx=5,pady=5) txt=Entry(self,font=fnt) txt.grid(row=r,column=1,columnspan=2,padx=5,pady=5) r=r+1 frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() lst=["Ram","Laxman","Seeta","Hanuman","Ravan", "Kishan","Arjun","Bheem","Dropadi","Karan"] p=iter(lst) for r in range(2): for c in range(5): self.b=Button(self,text=next(p)) self.b.grid(row=r,column=c,padx=5,pady=5) win=MyFrame() win.mainloop()